

forvalues m = 1(1)12 {

use "Stata_intermediate/PriceAggregation/CP_AGG_2004.dta",clear
keep if month == `m'
rename	dlog_TOR_CUM_AGG dlog_TOR_CUM_AGG_2004
rename 	dlogEV_AGG	dlogEV_AGG_2004
rename  dlogCV_AGG  dlogCV_AGG_2004
rename	p_LAS_CUM_AGG p_LAS_CUM_AGG_2004
rename 	p_PASS_CUM_AGG	p_PASS_CUM_AGG_2004
rename  p_FIS_CUM_AGG  p_FIS_CUM_AGG_2004
rename 	dlog_LAS_CUM_AGG  dlog_LAS_CUM_AGG_2004
rename  dlog_PASS_CUM_AGG  dlog_PASS_CUM_AGG_2004
gen diff_EV_TOR_2004 = dlogEV_AGG_2004 - dlog_TOR_CUM_AGG_2004


forvalues t = 2005(1)2019 {

merge m:1 yqVal using "Stata_intermediate\PriceAggregation\CP_AGG_`t'.dta"
keep if month == `m'
drop _merge 
rename	dlog_TOR_CUM_AGG  dlog_TOR_CUM_AGG_`t'
rename 	dlogEV_AGG	 dlogEV_AGG_`t'
rename  dlogCV_AGG   dlogCV_AGG_`t'
rename	p_LAS_CUM_AGG p_LAS_CUM_AGG_`t'
rename 	p_PASS_CUM_AGG	p_PASS_CUM_AGG_`t'
rename  p_FIS_CUM_AGG  p_FIS_CUM_AGG_`t'
rename 	dlog_LAS_CUM_AGG  dlog_LAS_CUM_AGG_`t'
rename  dlog_PASS_CUM_AGG  dlog_PASS_CUM_AGG_`t'
gen diff_EV_TOR_`t' = dlogEV_AGG_`t' - dlog_TOR_CUM_AGG_`t'

   } 

gen dlog_TOR_CUM_AGG_DIAG =.
gen dlogEV_AGG_DIAG =.
gen dlogCV_AGG_DIAG =.
gen	p_LAS_CUM_AGG_DIAG =.
gen	p_PASS_CUM_AGG_DIAG=.
gen p_FIS_CUM_AGG_DIAG = .
gen	dlog_LAS_CUM_AGG_DIAG = .
gen dlog_PASS_CUM_AGG_DIAG = .
gen half_Cov_DIAG = .
gen diff_EV_TOR_DIAG = . 

forvalues t = 2004(1)2019 {
replace dlog_TOR_CUM_AGG_DIAG = dlog_TOR_CUM_AGG_`t' if year == `t'
replace dlogEV_AGG_DIAG = dlogEV_AGG_`t' if year == `t'
replace dlogCV_AGG_DIAG = dlogCV_AGG_`t' if year == `t'
replace	p_LAS_CUM_AGG_DIAG = p_LAS_CUM_AGG_`t' if year == `t'
replace	p_PASS_CUM_AGG_DIAG= p_PASS_CUM_AGG_`t' if year == `t'
replace p_FIS_CUM_AGG_DIAG = p_FIS_CUM_AGG_`t' if year == `t'
replace	dlog_LAS_CUM_AGG_DIAG = dlog_LAS_CUM_AGG_`t' if year == `t'
replace dlog_PASS_CUM_AGG_DIAG = dlog_PASS_CUM_AGG_`t' if year == `t'
replace diff_EV_TOR_DIAG = diff_EV_TOR_`t' if year == `t'


   } 
  save "Stata_intermediate\Diag_Monthly_full\Diag_Monthly_`m'.dta", replace 
   
}

use "Stata_intermediate\Diag_Monthly_full\Diag_Monthly_1.dta",clear

forvalues m = 2(1)12 {
append using "Stata_intermediate\Diag_Monthly_full\Diag_Monthly_`m'.dta"
   } 


tset time 

generate Year =mdy(month,01,year)   
 format Year %tdy
   graph drop _all
drop if yqVal > 201905


cd "figdata\"

outsheet dlogEV_AGG_DIAG dlogCV_AGG_DIAG dlog_TOR_CUM_AGG_DIAG Year month using Monthly_welfare.csv , comma nolabel replace
